<template>
	<view>

		<view class="wrapper">

<view class="fill_header">
					<view class="fill_header_title">提醒</view>
					<view class="fill_info_cont clearfix remind ">USDT可转换为合约账户，合约收益转为USDT</view>
								
				
				</view>



			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">USDT</view>
					<view class="fill_info_cont clearfix">{{ userinfo.uMoney }}</view>
				</view>
			</view>
			

			

			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">合约账户</view>
					<view class="fill_info_cont clearfix">{{ userinfo.uLixi }}</view>
				</view>
			</view>
			
			
			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">合约收益</view>
					<view class="fill_info_cont clearfix">{{ userinfo.uTouZi }}</view>
				</view>
			</view>
			
			
			
			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">转出钱包</view>
					<view class="fill_info_cont clearfix">
						<view class="resultblack" @click="toggleTab('zhuanchu')">{{changeInfo.zhuanchu || '请选择转出钱包'}}</view>
						<w-picker mode="selector" defaultVal="" @confirm="onConfirm" :selectList="zhuanchuqianbao" ref="zhuanchu">
						</w-picker>

					</view>
				</view>
			</view>

			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">转入钱包</view>
					<view class="fill_info_cont clearfix">
						<view class="resultblack" @click="toggleTab('zhuanru')">{{changeInfo.zhuanru || '请选择转入钱包'}}</view>
						<w-picker mode="selector" defaultVal="" @confirm="onConfirmZhuanru" :selectList="zhuanruqianbao" ref="zhuanru">
						</w-picker>

					</view>
				</view>
			</view>



			<view class="cont">
				<view class="fill_info_line">
					<view class="fill_info_title">转换金额</view>
					<view class="fill_info_cont clearfix"><input type="number" v-model="changeInfo.money" placeholder="请输入数量" /></view>
				</view>
			</view>



			<view class="submit_btn_cont u-padding-bottom-40">
        <button :class="issubmit ? 'nosubmit_btn' : 'submit_btn'" @click="submit" :disabled="issubmit">提交</button>
      </view>
		</view>

	</view>
</template>

<script>
	import {
		CUser
	} from '@/common/cache/user.js';
	import validate from '@/common/ys-validate.js';
	import wpicker from "@/components/w-picker/w-picker.vue"
	var cache_user = new CUser();

	export default {
		data() {
			return {
				changeInfo: {
					zhuanchu: 'USDT账户',
					zhuanchuid: '2',
					zhuanru: '合约账户',
					zhuanruid: '4'
				},

				issubmit: false,
				userinfo: {},
				zhuanchuqianbao: [{
						'value': 2,
						'label': 'USDT账户'
					},
					{
							'value': 5,
							'label': '合约收益'
						}
				],
				zhuanruqianbao: [
					
					
					{
						'value': 4,
						'label': '合约账户'
					},{
						'value': 2,
						'label': 'USDT账户'
					}
					]
			};
		},
		components: {
			wpicker
		},
		onLoad() {
			this.getInfo();
		},

		onPullDownRefresh() {
			// 下拉监听事件
			this.getInfo();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},

		computed: {},
		methods: {
			getInfo(e) {
				cache_user.userinfo().then(res => {
					this.userinfo = res;
				});
			},
			//接收方法
			onConfirm(val) {
 
				this.changeInfo.zhuanchu = val.result;
				this.changeInfo.zhuanchuid = val.checkArr.value;
				 
			}, //接收方法
			onConfirmZhuanru(val) {

				this.changeInfo.zhuanru = val.result;
				this.changeInfo.zhuanruid = val.checkArr.value;
			},


			toggleTab(id) {
				this.$refs[id].show();
			},


			submit() {
				if (!validate.isNumber(this.changeInfo.money)) {
					this.$api.msg('输入金额有误');
					return false;
				}

				if (!this.changeInfo.zhuanchuid || !this.changeInfo.zhuanruid) {
					this.$api.msg('请选择转入传出钱包');
					return false;
				}
				
				if (this.changeInfo.zhuanchuid == this.changeInfo.zhuanruid) {
					this.$api.msg('转出转入钱包不能相同');
					return false;
				}

				var umoney = parseFloat(this.userinfo.uMoney);
				var uLixi = parseFloat(this.userinfo.uLixi);
				var uGrantMoney = parseFloat(this.userinfo.uGrantMoney);
				var uDTSM = parseFloat(this.userinfo.uDTSM);
				var changemoney = parseFloat(this.changeInfo.money);

				if (changemoney <= 0) {

					this.$api.msg('转出金额不能小于0');
					return false;
				}


				if (this.changeInfo.zhuanchuid == 2) {
					//转出小于转入
					if (umoney < changemoney) {
						this.$api.msg('您的转出金额不得大于现有金额');
						return false;
					}
				} else if (this.changeInfo.zhuanchuid == 5) {
					//转出小于转入
					if (uGrantMoney < changemoney) {
						this.$api.msg('您的转出金额不得大于现有金额');
						return false;
					}
				}else if (this.changeInfo.zhuanchuid == 6) {
					//转出小于转入
					if (uDTSM < changemoney) {
						this.$api.msg('您的转出金额不得大于现有金额');
						return false;
					}
				}


				this.issubmit = true; //禁用按钮
				var _self = this;
				this.$api.http.post('assistance/moneychange/changeAccounts', this.changeInfo).then(res => {
					if (res.status == 200) {
						//成功执行
						uni.showToast({
							icon: 'none',
							title: res.msg,
							mask: true,
							success() {
								uni.removeStorageSync('my');//清除我的信息
								_self.getInfo();
							}
						});
					} else {
						this.issubmit = false; //启用按钮
						uni.showToast({
							icon: 'none',
							title: res.msg,
							mask: true
						});

						return false;
					}
				});
			}
		},
	}
</script>

<style lang="scss">
	.remind {
		color: #f1c013;
		font-size: 26upx;
	}

	.clearfix {
		zoom: 1;
		display: block;
	}

	.noShow {
		display: none;
	}

	.clearfix:after {
		content: '.';
		visibility: hidden;
		display: block;
		height: 0;
		clear: both;
	}




	.wrapper {

    color: $color-theme;
		background-color: $bg-gap;
		min-height: 100vh;
		padding: 20upx;

		.fill_header {
			border-radius: 5upx;
			background-color: $bg-theme;
			padding: 40upx;
			margin-bottom: 20upx;

			.fill_header_title {
				font-size: 26upx;
			}

			.fill_header_cont {
				margin-top: 30upx;

				.photo_img_cont {
					border: 1upx solid hsla(0, 0%, 60%, 0.3);
					width: 120upx;
					height: 120upx;
					padding: 20upx;

					.photo_img {
						width: 80upx;
						height: 80upx;
					}
				}
			}
		}

		.cont {
			border-radius: 5upx;
			background-color: $bg-theme;
			padding: 40upx;

			.fill_info_line {
				margin-top: 30upx;

				.fill_info_title {
					font-size: 26upx;
				}

				.fill_info_cont {
					position: relative;
					border-bottom: 1upx solid hsla(0, 0%, 60%, 0.3);
          color: $text-color;
					.pwdInput {
						font-size: 26upx;
						height: 80upx;
						line-height: 80upx;
						border: none;
						display: block;
						outline: none;
					}

					.pwd_icon {
						width: 85upx;
						height: 85upx;
						-webkit-transform: scale(0.4);
						transform: scale(0.4);
						position: absolute;
						top: 0;
						right: 0;
					}
				}

				.fill_info_another {
					border-bottom: 1upx solid hsla(0, 0%, 60%, 0.3);
					margin-top: 24upx;

					label {
						font-size: 14upx;
					}
				}

				.checkbox_line {
					padding: 0 0px 14px;

					.uni-input {
						text-indent: 0;
						background: #ffffff;
					}
				}
			}

			.fill_info_line:first-child {
				margin-top: 0;
			}
		}
	}

	.submit_btn_cont {
		margin-top: 20upx;

		.submit_btn {
			border-radius: 5upx;
			color: #ffffff;
			font-size: 26upx;
			background: linear-gradient(90deg, #4e8cff, #2f79ff);
		}

		.nosubmit_btn {
			border-radius: 5upx;
			color: #ffffff;
			font-size: 26upx;
			background: linear-gradient(90deg, #c6c5c5, #cdced0);
		}
	}
</style>
